﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using TanmiaGrp.Basis.Specification;

namespace TanmiaGrp.GeneralLedger.IRepository.Basis
{
    public interface IGenericQueryRepository
    {
         /// <summary>
        /// Returns single BusinessObject of table that satisfies a specified condition or a null if no such element is found.
        /// </summary>
        /// <typeparam name="T">The type of BusinessObject of source table.</typeparam>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>The BusinessObject the satisfy the predicate.</returns>
        T Single<T>(Expression<Func<T, bool>> predicate) where T : class;

        T Load<T>(ISpecification<T> spec) where T : class;

        List<T> LoadAll<T>(ISpecification<T> spec) where T : class;

        /// <summary>
        /// Load a list of <see cref="TBizEntity"/> according to specific conditions and sorting.
        /// </summary>
        /// <typeparam name="TBizEntity">The Business Entity type to be loaded.</typeparam>
        /// <typeparam name="TOrderProp">The ordering columns</typeparam>
        /// <param name="spec">Specification of searching and filtering.</param>
        /// <param name="orderBy">Ordering columns.</param>
        /// <returns></returns>
        List<TBizEntity> LoadAll<TBizEntity, TOrderProp>(ISpecification<TBizEntity> spec, Expression<Func<TBizEntity, TOrderProp>> orderBy) where TBizEntity : class;

        bool Matches<T>(ISpecification<T> spec) where T : class;

        /// <summary>
        /// Returns the number of elements of the specified T BusinessEntity that satisfies a condition.
        /// </summary>
        /// <typeparam name="T">The type of BusinessObject of source table.</typeparam>
        /// <param name="predicate">A function to test each element for a condition.</param>
        /// <returns>The number of elements in the sequence that satisfies the condition in the predicate function.</returns>
        int GetCount<T>(Expression<Func<T, bool>> predicate) where T : class;

        /// <summary>
        /// Returns the number of elements in a BusinessObject's table.
        /// </summary>
        /// <typeparam name="T">The type of BusinessObject of source table.</typeparam>
        /// <returns>The number of elements in the input sequence.</returns>
        int GetCount<T>() where T : class;
    }
}
